# -*- encoding: utf-8 -*-
'''
@File    :   mongo_utils.py
@Time    :   2025-11-09 11:58:32
@Author  :   simon
@Version :   1.0
@Contact :   yonglonggeng@163.com
@License :   (C)Copyright 1994-2024, Liugroup-NLPR-CASIA
@Desc    :   数据库工具类
@WeChat  :   Herbert·Simon
'''

# here put the import lib
from bson.objectid import ObjectId

def make_id_str(doc):
    if doc and "_id" in doc and isinstance(doc["_id"], ObjectId):
        doc["_id"] = str(doc["_id"])
    return doc

def make_ids_str(docs):
    if isinstance(docs, list):
        return [make_id_str(doc.copy()) for doc in docs]
    else:
        return make_id_str(docs.copy())


if __name__ == "__main__":
    # 测试 make_id_str 函数
    doc = {"_id": ObjectId("654f2a2f1234567890123456")}
    print(make_id_str(doc))
    docs=[{"_id": ObjectId("654f2a2f1234567890123456")},{"_id": ObjectId("654f2a2f1234567890123457")}]
    print(make_ids_str(docs))
